//
//  MessageUtils.m
//
//  Created by Guillaume SOURDRILLE on 19/02/12.
//  Copyright (c) 2012 Edenyorke. All rights reserved.
//

#import "MessageUtils.h"

@implementation MessageUtils

- (void)initData {
    
    NSString *path = [self getDocumentPath];
    NSMutableDictionary *unDict = [NSMutableDictionary dictionaryWithContentsOfFile:path];
    if (!unDict){
        unDict = [[NSMutableDictionary alloc]init];
        [unDict setValue:@"" forKey:@"ipxkey"];
        [unDict setValue:@"" forKey:@"gamertag"]; 
        [unDict setValue:@"ON" forKey:@"banner"]; 
        
    }
    
    [unDict setValue:@"v1.4" forKey:@"version"];
    [unDict writeToFile:path atomically:YES];
    
}

-(NSString*) getDocumentPath{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"xkeyInterface.plist"];
   
    
    return path;

}


- (NSString*) getValue:(NSString *)key{
    
    NSString *path = [self getDocumentPath];
    NSMutableDictionary *dico = [NSMutableDictionary dictionaryWithContentsOfFile:path];
    if (!dico){
        [self initData];
    }
    NSString *value = [dico valueForKey:key];
    return value;
    
}



- setValue:(NSString *)key value:(NSString*)value{
    
    NSString *path = [self getDocumentPath];
    NSMutableDictionary *dico = [NSMutableDictionary dictionaryWithContentsOfFile:path];
    if (!dico){
        [self initData];
    }
   [dico setValue:value forKey:key];
    [dico writeToFile:path atomically:YES];
    
 

       
      return nil;
}

@end
